package com.dingwen.treasure.manage.controller;

import com.dingwen.treasure.manage.dto.SysConfigDto;
import com.dingwen.treasure.manage.vo.SysConfigVo;
import com.dingwen.treasure.model.entity.mybatisplus.SysConfig;
import com.dingwen.treasure.mybatisplus.controller.AbstractBaseControllerMybatisPlusImpl;
import com.dingwen.treasure.mybatisplus.util.SysConfigUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 　SysConfigController
 * 　@author dingwen
 * 　@date 2022/5/16$
 */
@Api(tags = "统一系统配置解决方案")
@RestController
@Slf4j
@RequestMapping("sys/configs")
public class SysConfigController extends AbstractBaseControllerMybatisPlusImpl<SysConfig, SysConfigDto, SysConfigVo> {

    /**
     * 系统配置
     */
    @Resource
    private  SysConfigUtil sysConfigUtil;


    /**
     * 系统配置测试 </br>
     * <p> 权限测试</p>
     */
    @ApiOperation(value = "系统配置测试")
    @GetMapping("test")
    @PreAuthorize("@pm.hasPerm('batch_run:download')")
    public void test() {
        String str1 = sysConfigUtil.getValueOrDefault("test", "test");
        String str2 = sysConfigUtil.getValueOrDefault("sys_one", "test");
        String str3 = sysConfigUtil.getValueOrDefault("business_one", "test");

        log.info(str1);
        log.info(str2);
        log.info(str3);

    }

    /**
     * 默认开启 BO 到 VO 的转换
     *
     * @return {@link Boolean}
     */
    @Override
    public Boolean enableBoToVo() {
        return false;
    }
}
